<?php

include_once "config/config.php";

include_once "lib/employee_class.php";

include_once "lib/pdodbmanager.php";
include_once "lib/senitize.php";

$pdo_obj=new PDODBMNanager(HOST,DB,USERNAME,PASS);

$sen_obj=new SanitizeInput();

$general_obj=new General();

include_once "lib/functions.php";

//$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);

$array_width=array("A"=>15);


if(isset($_POST['type_table']) && $_POST['type_table']!="")
{
	if($_POST['type_table']=="Salary")
	{
		//$columns=array("Employee Code","Type Name","First Name","Last Name","Salary Effective Date","Previous CTC","Current CTC","Basic","HRA","Conveyence","Performance Allowance","Next Increment Date","Date of Previous Increment","Bank Account Number");
        $columns=array("Employee Code","Type Name","First Name","Last Name","Designation","Supervisor","Assistant Manager","Manager","Salary Effective Date","Previous CTC","Current CTC","Basic","HRA","Conveyence","Performance Allowance","Next Increment Date","Bank Account Number");
        $array_width["Q"]=20;
		$title="Employee Salary Structure";
		$filename="employee_salary_structure.xls";
		$condition=$_POST['condition']." and salary.ecode=users.ecode and users.type_id = user_types.id and salary.salary_effective_date<='".time()."'  and users.employee_status='Current Employee'"; 
		//echo $condition;
		//die;
		if($_POST['title']=="id")
			$_POST['order']="desc";
			
		$res_query=$general_obj->search_record($pdo_obj," salary.*,user_type,users.first_name,users.last_name,emp_designation,team_id "," users,user_types,salary ",$condition," salary.id desc,".$_POST['title'],$_POST['order']);
		$result=array();
        $ecodearr=array();
		if(count($res_query)>0)
		{
		    $j=0;
			for($i=0;$i<count($res_query);$i++)
			{
			    if(in_array($res_query[$i]['ecode'],$ecodearr))
                {
                    continue;
                }
                else
                {
                    $ecodearr[]=$res_query[$i]['ecode'];
                
    				$dopi="";$doni="";$sod="";
                    $designation="";
                    $supervisor="";
                    $am="";
                    $manager="";
    				if(isset($res_query[$i]['donincrement']) && $res_query[$i]['donincrement']!=0)
    					$doni=date("m/d/Y",$res_query[$i]['donincrement']);
    				/*
    				if(isset($res_query[$i]['dopincrement']) && $res_query[$i]['dopincrement']!=0)
    					$dopi=date("m/d/Y",$res_query[$i]['dopincrement']);
    				*/
                    if($res_query[$i]['emp_designation']>0)
                    {
                        $designationinfo=$general_obj->search_record($pdo_obj," designation "," designations ","id='".$res_query[$i]['emp_designation']."'","id","asc");
                        if(count($designationinfo)>0)
                        {
                            $designation=$designationinfo[0]['designation'];
                        }
                    }
                    
                    if($res_query[$i]['team_id']>0 && ($res_query[0]['user_type']=="Agent/Employee" || $res_query[0]['user_type']=="HR Executive" || $res_query[0]['user_type']=="Transport Executive" || $res_query[0]['user_type']=="Quality Executive" || $res_query[0]['user_type']=="Training Agent" || $res_query[0]['user_type']=="Desktop Engineer"))
                    {
                        $teaminfo=$general_obj->search_record($pdo_obj," supervisor_id,am_id,ops_manager_id "," teams ","id='".$res_query[$i]['team_id']."'","id","asc");
                        
                        if(count($teaminfo)>0)
                        {
                            if($teaminfo[0]['supervisor_id']>0)
                            {
                                $generalinfo=$general_obj->search_record($pdo_obj," first_name,last_name,ecode "," users ","id='".$teaminfo[0]['supervisor_id']."'","id","asc");
                                if(count($generalinfo)>0)
                                {
                                    $supervisor=trim($generalinfo[0]['first_name']." ".$generalinfo[0]['last_name'])." ( ".$generalinfo[0]['ecode']." )";
                                }
                            }
                            if($teaminfo[0]['am_id']>0)
                            {
                                $generalinfo=$general_obj->search_record($pdo_obj," first_name,last_name,ecode "," users ","id='".$teaminfo[0]['am_id']."'","id","asc");
                                if(count($generalinfo)>0)
                                {
                                    $am=trim($generalinfo[0]['first_name']." ".$generalinfo[0]['last_name'])." ( ".$generalinfo[0]['ecode']." )";
                                }
                            }
                            if($teaminfo[0]['ops_manager_id']>0)
                            {
                                $generalinfo=$general_obj->search_record($pdo_obj," first_name,last_name,ecode "," users ","id='".$teaminfo[0]['ops_manager_id']."'","id","asc");
                                if(count($generalinfo)>0)
                                {
                                    $manager=trim($generalinfo[0]['first_name']." ".$generalinfo[0]['last_name'])." ( ".$generalinfo[0]['ecode']." )";
                                }
                            }
                        }
                        
                    }
                    else if($res_query[0]['user_type']=="Supervisor")
                    {
                        $teaminfo=$general_obj->search_record($pdo_obj," am_id,ops_manager_id "," teams ","supervisor_id='".$res_query[$i]['id']."'","id","asc");
                        
                        if(count($teaminfo)>0)
                        {
                            if($teaminfo[0]['am_id']>0)
                            {
                                $generalinfo=$general_obj->search_record($pdo_obj," first_name,last_name,ecode "," users ","id='".$teaminfo[0]['am_id']."'","id","asc");
                                if(count($generalinfo)>0)
                                {
                                    $am=trim($generalinfo[0]['first_name']." ".$generalinfo[0]['last_name'])." ( ".$generalinfo[0]['ecode']." )";
                                }
                            }
                            if($teaminfo[0]['ops_manager_id']>0)
                            {
                                $generalinfo=$general_obj->search_record($pdo_obj," first_name,last_name,ecode "," users ","id='".$teaminfo[0]['ops_manager_id']."'","id","asc");
                                if(count($generalinfo)>0)
                                {
                                    $manager=trim($generalinfo[0]['first_name']." ".$generalinfo[0]['last_name'])." ( ".$generalinfo[0]['ecode']." )";
                                }
                            }
                        }
                    }
                    else if($res_query[0]['user_type']=="Assistant Manager" || $res_query[0]['user_type']=="Quality AM" || $res_query[0]['user_type']=="Trainer")
                    {
                        $teaminfo=$general_obj->search_record($pdo_obj," distinct ops_manager_id "," teams ","am_id='".$res_query[$i]['id']."'","id","asc");
                        
                        for($k=0;$k<($teaminfo);$k++)
                        {
                            if($teaminfo[0]['ops_manager_id']>0)
                            {
                                $generalinfo=$general_obj->search_record($pdo_obj," first_name,last_name,ecode "," users ","id='".$teaminfo[0]['ops_manager_id']."'","id","asc");
                                if(count($generalinfo)>0)
                                {
                                    $manager.=trim($generalinfo[0]['first_name']." ".$generalinfo[0]['last_name'])." ( ".$generalinfo[0]['ecode']." )".",";
                                }
                            }
                        }
                        if(count($teaminfo)>0)
                        {
                            $manager=substr($manager,0,strlen($manager)-1);
                        }
                    }
                    
    				if(isset($res_query[$i]['salary_effective_date']) && $res_query[$i]['salary_effective_date']!=0)
    					$sod=date("m/d/Y",$res_query[$i]['salary_effective_date']);
    					
    					
    				$result[$j]=array($res_query[$i]['ecode'],$res_query[$i]['user_type'],trim($res_query[$i]['first_name']),$res_query[$i]['last_name'],$designation,$supervisor,$am,$manager,$sod,$res_query[$i]['previous_ctc'],$res_query[$i]['ctc'],$res_query[$i]['basic'],$res_query[$i]['hra'],$res_query[$i]['conveyence'],$res_query[$i]['performance_allowance'],$doni,$res_query[$i]['bankaccount_number']);
                    $j++;
                }
			}
		}
	}
	else if($_POST['type_table']=="Education")
	{
		$columns=array("Employee Code","Type Name","First Name","Last Name","PG University","PG Passing Year","PG Percent","UG University","UG Passing year","UG Percent","Senior Board","Senior Passing year","Senior Percent","Secondary Board","Secondary Passing year","Secondary Percent");
		$title="Employee Education";
		$filename="employee_educational_info.xls";
		$condition=$_POST['condition']." and educational_information.ecode=users.ecode and educational_information.status='Current'"; 
		
		$res_query=$general_obj->search_record($pdo_obj," educational_information.*,user_type,users.first_name,users.last_name "," users,user_types,educational_information ",$condition,$_POST['title'],$_POST['order']);
		$result=array();
		if(count($res_query)>0)
		{
			for($i=0;$i<count($res_query);$i++)
			{
				$result[$i]=array($res_query[$i]['ecode'],$res_query[$i]['user_type'],trim($res_query[$i]['first_name']),$res_query[$i]['last_name'],$res_query[$i]['pg_university'],$res_query[$i]['pg_year'],$res_query[$i]['pg_percent'],$res_query[$i]['ug_university'],$res_query[$i]['ug_year'],$res_query[$i]['ug_percent'],$res_query[$i]['senior_board'],$res_query[$i]['senior_year'],$res_query[$i]['senior_percent'],$res_query[$i]['secondary_board'],$res_query[$i]['secondary_year'],$res_query[$i]['secondary_percent']);
			}
		}
	}
	else if($_POST['type_table']=="Employee")// Employee users table
	{
		$columns=array("Employee Code","Type Name","First Name","Last Name","Email Id","DOB","Gender","Marital Status","Anniversary Date","Contact No","Emergency Contact No","Current Address","Current City","Current State","Current PIN","Current Zone","Current Area","Current Route","Permanent Address","Parmanent City","Parmanent State","Parmanent PIN","Blood Group","DOJ","Cab Avail","Process","Department","Designation","TP Designation","TP Process","Training Status","Band","Team","PAN Number","Status","Comp off Leave Balance","Normal Paid Leaves Taken","Pickup Default Cab","Drop Default Cab","Heirarchy","Supervisor","Assistant Manager","Manager");
		$title="Employee Report";
		$filename="employee_Report.xls";
		//echo count($columns);
		
		$res_query=$general_obj->search_record($pdo_obj," users.*,user_type "," users,user_types ",$_POST['condition'],$_POST['title'],$_POST['order']);
		$result=array();
		if(count($res_query)>0)
		{
			for($i=0;$i<count($res_query);$i++)
			{
				$current_route="";$current_area="";$current_zone="";$process="";$department="";$designation="";$team="";$heirarchy_nm="";
                $manager="";
                $am="";
                $supervisor="";
                
				if(isset($res_query[$i]['team_id']) && $res_query[$i]['team_id']!=0)
					$team=$general_obj->get_field_value($pdo_obj,"teams","id=".$res_query[$i]['team_id'],"team_name");
					
				if(isset($res_query[$i]['current_route_id']) && $res_query[$i]['current_route_id']!=0)
					$current_route=$general_obj->get_field_value($pdo_obj,"routes","id=".$res_query[$i]['current_route_id'],"route_name");
				
				if(isset($res_query[$i]['current_area_id']) && $res_query[$i]['current_area_id']!=0)	
					$current_area=$general_obj->get_field_value($pdo_obj,"areas","id=".$res_query[$i]['current_area_id'],"area_name");
				
				if(isset($res_query[$i]['current_zone_id']) && $res_query[$i]['current_zone_id']!=0)	
					$current_zone=$general_obj->get_field_value($pdo_obj,"zones","id=".$res_query[$i]['current_zone_id'],"zone_name");
				if(isset($res_query[$i]['emp_process']) && $res_query[$i]['emp_process']!=0)	
					$process=$general_obj->get_field_value($pdo_obj,"processes","id=".$res_query[$i]['emp_process'],"process_name");
				if(isset($res_query[$i]['department']) && $res_query[$i]['department']!=0)	
					$department=$general_obj->get_field_value($pdo_obj,"departments","id=".$res_query[$i]['department'],"dept_name");
				if(isset($res_query[$i]['emp_designation'])&& $res_query[$i]['emp_designation']!=0)	
					$designation=$general_obj->get_field_value($pdo_obj,"designations","id=".$res_query[$i]['emp_designation'],"designation");
					
				if(isset($res_query[$i]['heirarchy_id'])&& $res_query[$i]['heirarchy_id']!=0)	
					$heirarchy_nm=$general_obj->get_field_value($pdo_obj,"heirarchy","id=".$res_query[$i]['heirarchy_id'],"heirarchy_name");	
				
				$dob="";$doj="";$aniversary="";
				if($res_query[$i]['dob']!=0 && $res_query[$i]['dob']!="")
				{
					$dob=date("m/d/Y",$res_query[$i]['dob']);
				}	
				if($res_query[$i]['doj']!=0 && $res_query[$i]['doj']!="")
				{
					$doj=date("m/d/Y",$res_query[$i]['doj']);
				}
				if($res_query[$i]['anniversary_date']!="" && $res_query[$i]['anniversary_date']!=0)
				{
					$aniversary=date("m/d/Y",$res_query[$i]['anniversary_date']);
				}
                
                if($res_query[$i]['team_id']>0 && ($res_query[0]['user_type']=="Agent/Employee" || $res_query[0]['user_type']=="HR Executive" || $res_query[0]['user_type']=="Transport Executive" || $res_query[0]['user_type']=="Quality Executive" || $res_query[0]['user_type']=="Training Agent" || $res_query[0]['user_type']=="Desktop Engineer"))
                {
                    $teaminfo=$general_obj->search_record($pdo_obj," supervisor_id,am_id,ops_manager_id "," teams ","id='".$res_query[$i]['team_id']."'","id","asc");
                    
                    if(count($teaminfo)>0)
                    {
                        if($teaminfo[0]['supervisor_id']>0)
                        {
                            $generalinfo=$general_obj->search_record($pdo_obj," first_name,last_name,ecode "," users ","id='".$teaminfo[0]['supervisor_id']."'","id","asc");
                            if(count($generalinfo)>0)
                            {
                                $supervisor=trim($generalinfo[0]['first_name']." ".$generalinfo[0]['last_name'])." ( ".$generalinfo[0]['ecode']." )";
                            }
                        }
                        if($teaminfo[0]['am_id']>0)
                        {
                            $generalinfo=$general_obj->search_record($pdo_obj," first_name,last_name,ecode "," users ","id='".$teaminfo[0]['am_id']."'","id","asc");
                            if(count($generalinfo)>0)
                            {
                                $am=trim($generalinfo[0]['first_name']." ".$generalinfo[0]['last_name'])." ( ".$generalinfo[0]['ecode']." )";
                            }
                        }
                        if($teaminfo[0]['ops_manager_id']>0)
                        {
                            $generalinfo=$general_obj->search_record($pdo_obj," first_name,last_name,ecode "," users ","id='".$teaminfo[0]['ops_manager_id']."'","id","asc");
                            if(count($generalinfo)>0)
                            {
                                $manager=trim($generalinfo[0]['first_name']." ".$generalinfo[0]['last_name'])." ( ".$generalinfo[0]['ecode']." )";
                            }
                        }
                    }
                    
                }
                else if($res_query[0]['user_type']=="Supervisor")
                {
                    $teaminfo=$general_obj->search_record($pdo_obj," am_id,ops_manager_id "," teams ","supervisor_id='".$res_query[$i]['id']."'","id","asc");
                    
                    if(count($teaminfo)>0)
                    {
                        if($teaminfo[0]['am_id']>0)
                        {
                            $generalinfo=$general_obj->search_record($pdo_obj," first_name,last_name,ecode "," users ","id='".$teaminfo[0]['am_id']."'","id","asc");
                            if(count($generalinfo)>0)
                            {
                                $am=trim($generalinfo[0]['first_name']." ".$generalinfo[0]['last_name'])." ( ".$generalinfo[0]['ecode']." )";
                            }
                        }
                        if($teaminfo[0]['ops_manager_id']>0)
                        {
                            $generalinfo=$general_obj->search_record($pdo_obj," first_name,last_name,ecode "," users ","id='".$teaminfo[0]['ops_manager_id']."'","id","asc");
                            if(count($generalinfo)>0)
                            {
                                $manager=trim($generalinfo[0]['first_name']." ".$generalinfo[0]['last_name'])." ( ".$generalinfo[0]['ecode']." )";
                            }
                        }
                    }
                }
                else if($res_query[0]['user_type']=="Assistant Manager" || $res_query[0]['user_type']=="Quality AM" || $res_query[0]['user_type']=="Trainer")
                {
                    $teaminfo=$general_obj->search_record($pdo_obj," distinct ops_manager_id "," teams ","am_id='".$res_query[$i]['id']."'","id","asc");
                    
                    for($k=0;$k<($teaminfo);$k++)
                    {
                        if($teaminfo[0]['ops_manager_id']>0)
                        {
                            $generalinfo=$general_obj->search_record($pdo_obj," first_name,last_name,ecode "," users ","id='".$teaminfo[0]['ops_manager_id']."'","id","asc");
                            if(count($generalinfo)>0)
                            {
                                $manager.=trim($generalinfo[0]['first_name']." ".$generalinfo[0]['last_name'])." ( ".$generalinfo[0]['ecode']." )".",";
                            }
                        }
                    }
                    if(count($teaminfo)>0)
                    {
                        $manager=substr($manager,0,strlen($manager)-1);
                    }
                }
                
				$result[$i]=array($res_query[$i]['ecode'],$res_query[$i]['user_type'],trim($res_query[$i]['first_name']),$res_query[$i]['last_name'],$res_query[$i]['email_id'],$dob,$res_query[$i]['gender'],$res_query[$i]['marital_status'],$aniversary,$res_query[$i]['contact_number'],$res_query[$i]['emergency_contact_number'],$res_query[$i]['current_address'],$res_query[$i]['current_city'],$res_query[$i]['current_state'],$res_query[$i]['current_pin'],$current_zone,$current_area,$current_route,$res_query[$i]['permanent_address'],$res_query[$i]['parmanent_city'],$res_query[$i]['parmanent_state'],$res_query[$i]['parmanent_pin'],$res_query[$i]['blood_group'],$doj,$res_query[$i]['cab_avail'],$process,$department,$designation,$res_query[$i]['designation'],$res_query[$i]['process'],$res_query[$i]['training_status'],$res_query[$i]['band'],$team,$res_query[$i]['pan_number'],$res_query[$i]['status'],$res_query[$i]['comp_off_leave_balance'],$res_query[$i]['leaves_taken'],$res_query[$i]['pickup_default_cab'],$res_query[$i]['drop_default_cab'],$heirarchy_nm,$supervisor,$am,$manager);
			}
		}
	}
	else if($_POST['type_table']=="Employee Increment")// Employee users table
	{
		//$columns=array("Employee Code","Type Name","First Name","Last Name","Date of Joining","Date of Next Increment","Date of Previous Increment");
		$columns=array("Employee Code","Type Name","First Name","Last Name","Salary Effective Date","Previous CTC","Current CTC","Basic","HRA","Conveyence","Performance Allowance","Date of Next Increment","Date of Previous Increment","Salary Change Percent","Salary Change Amount","Salary Change Reason");
		$title="Employee Increment Report";
		$filename="employee_increment_Report.xls";
		//echo count($columns);
		$_POST['condition'].=" and salary.ecode=users.ecode and salary.salary_change_reason in ('Increment','Promotion') and salary.status='Current'";
		$res_query=$general_obj->search_record($pdo_obj," first_name,last_name,user_type,salary.* "," users,user_types,salary ",$_POST['condition'],$_POST['title'],$_POST['order']);
		$result=array();
		if(count($res_query)>0)
		{
			for($i=0;$i<count($res_query);$i++)
			{
				$dopi="";$doni="";$sod="";
				if(isset($res_query[$i]['donincrement']) && $res_query[$i]['donincrement']!=0)
					$doni=date("m/d/Y",$res_query[$i]['donincrement']);
				
				if(isset($res_query[$i]['dopincrement']) && $res_query[$i]['dopincrement']!=0)
					$dopi=date("m/d/Y",$res_query[$i]['dopincrement']);
					
				
				if(isset($res_query[$i]['salary_effective_date']) && $res_query[$i]['salary_effective_date']!=0)
					$sod=date("m/d/Y",$res_query[$i]['salary_effective_date']);
					
					
				$result[$i]=array($res_query[$i]['ecode'],$res_query[$i]['user_type'],trim($res_query[$i]['first_name']),$res_query[$i]['last_name'],$sod,$res_query[$i]['previous_ctc'],$res_query[$i]['ctc'],$res_query[$i]['basic'],$res_query[$i]['hra'],$res_query[$i]['conveyence'],$res_query[$i]['performance_allowance'],$doni,$dopi,$res_query[$i]['salary_change_percent'],$res_query[$i]['salary_change_amount'],$res_query[$i]['salary_change_reason']);	
				//$result[$i]=array($res_query[$i]['ecode'],$res_query[$i]['user_type'],trim($res_query[$i]['first_name']),$res_query[$i]['last_name'],$doj,$doni,$dopi);
			}
		}
		//die;
	}
    else if($_POST['type_table']=="Employee Compliance")// Employee Compliance table
	{
		$columns=array("Employee Code","Employee First Name","Employee Last Name","Letter - Severity |","Letter - Severity ||","Letter - Severity |||");
		$title="Employee Compliance Report";
		$filename="employee_compliance_Report.xls";
		
		$res_query=$general_obj->search_record($pdo_obj," emp_compliance.*,first_name,last_name "," users,emp_compliance ",$_POST['condition'],$_POST['title'],$_POST['order']);
		$result=array();
		if(count($res_query)>0)
		{
			for($i=0;$i<count($res_query);$i++)
			{
				$sevrity1="";$sevrity2="";$sevrity3="";
				if(isset($res_query[$i]['severity_1']) && $res_query[$i]['severity_1']!=0)
					$sevrity1=date("m/d/Y",$res_query[$i]['severity_1']);
				
				if(isset($res_query[$i]['severity_2']) && $res_query[$i]['severity_2']!=0)
					$sevrity2=date("m/d/Y",$res_query[$i]['severity_2']);
					
				if(isset($res_query[$i]['severity_3']) && $res_query[$i]['severity_3']!=0)
					$sevrity3=date("m/d/Y",$res_query[$i]['severity_3']);		
				
					
				$result[$i]=array($res_query[$i]['ecode'],$res_query[$i]['first_name'],trim($res_query[$i]['last_name']),$sevrity1,$sevrity2,$sevrity3);
			}
		}
	}
    else if($_POST['type_table']=="Employee Resigned")// Resigned Employee table
	{
		$columns=array("Employee Code","Full Name","Resignation Date","Relieving Date","Last Working Date","Leaving Reason");
		$title="Exit Employees Report";
		$filename="exit_employee_Report.xls";
		
		$res_query=$general_obj->search_record($pdo_obj," resign_employees.*,reason "," resign_employees,relieve_reasons ",$_POST['condition'],$_POST['title'],$_POST['order']);
		$result=array();
		if(count($res_query)>0)
		{
			for($i=0;$i<count($res_query);$i++)
			{
				$resigndate="";$relievedate="";$lastworkdate="";
				if(isset($res_query[$i]['resignation_date']) && $res_query[$i]['resignation_date']!=0)
					$resigndate=date("m/d/Y",$res_query[$i]['resignation_date']);
				
				if(isset($res_query[$i]['relieving_date']) && $res_query[$i]['relieving_date']!=0)
					$relievedate=date("m/d/Y",$res_query[$i]['relieving_date']);
					
				if(isset($res_query[$i]['last_working_date']) && $res_query[$i]['last_working_date']!=0)
					$lastworkdate=date("m/d/Y",$res_query[$i]['last_working_date']);		
					
				$result[$i]=array($res_query[$i]['ecode'],$res_query[$i]['full_name'],$resigndate,$relievedate,$lastworkdate,$res_query[$i]['reason']);
			}
		}
	}
    else if($_POST['type_table']=="Employee Docs List")
    {
        $doctypeslist=$general_obj->search_record($pdo_obj," doctype,id "," doctypes "," status='Active' ","doctype","asc",0);
        $columns=array("Employee Code","Full Name","Hire Date","Process","Department","Designation");
        for($j=0;$j<count($doctypeslist);$j++)
        {
             $columns[]=$doctypeslist[$j]['doctype']; 
        }
        
		$title="Employees Documents Report";
		$filename="employee_doc_Report.xls";
		
		$res_query=$general_obj->search_record($pdo_obj," ecode,first_name,last_name,team_id,doj,process_name,dept_name,designations.designation "," users,processes,departments,designations ",$_POST['condition'],$_POST['title'],$_POST['order']);
		$result=array();
		if(count($res_query)>0)
		{
			for($i=0;$i<count($res_query);$i++)
			{
				$result[$i]=array($res_query[$i]['ecode'],trim($res_query[$i]['first_name'])." ".trim($res_query[$i]['last_name']),date("m/d/Y",$res_query[$i]['doj']),$res_query[$i]['process_name'],$res_query[$i]['dept_name'],$res_query[$i]['designation']);
                for($j=0;$j<count($doctypeslist);$j++)
                {
                    $empdocinfo=$general_obj->search_record($pdo_obj," id "," emp_docs "," ecode='".$res_query[$i]['ecode']."' and doctype_id='".$doctypeslist[$j]['id']."' and status='Active' ","id","desc",0);
                    if(count($empdocinfo)>0)
                    {
                         $result[$i][]=count($empdocinfo);
                    }
                    else
                    {
                        $result[$i][]="-";
                    }
                }
			}
		}
    }
    else if($_POST['type_table']=="Employer")
    {
		$columns=array("Employee Code","Type Name","Full Name","Previous Employer 1","Joining Date 1","Leaving Date 1","Experience 1","Previous Employer 2","Joining Date 2","Leaving Date 2","Experience 2","Previous Employer 3","Joining Date 3","Leaving Date 3","Experience 3");
		$title="Employee Employment";
		$filename="employee_employment_info.xls";
		
	//	print_r($_POST['condition']);
//		print_r($_POST);
//		die;
		$condition=$_POST['condition']." and previous_employment.ecode=users.ecode and previous_employment.status='Current'"; 
		
		$res_query=$general_obj->search_record($pdo_obj," previous_employment.*,user_type,users.first_name,users.last_name "," users,user_types,previous_employment ",$condition,$_POST['title'],$_POST['order']);
		$result=array();
		if(count($res_query)>0)
		{
			for($i=0;$i<count($res_query);$i++)
			{
				$jod1="";$jod2="";$jod3="";$ld1="";$ld2="";$ld3="";
				if(isset($res_query[$i]['joining_date1']) && $res_query[$i]['joining_date1']!=0)
    				$jod1=date("m/d/Y",$res_query[$i]['joining_date1']);
    				
    			if(isset($res_query[$i]['joining_date2']) && $res_query[$i]['joining_date2']!=0)
    				$jod2=date("m/d/Y",$res_query[$i]['joining_date2']);
    				
    			if(isset($res_query[$i]['joining_date3']) && $res_query[$i]['joining_date3']!=0)
    				$jod3=date("m/d/Y",$res_query[$i]['joining_date3']);
    			
				if(isset($res_query[$i]['leaving_date1']) && $res_query[$i]['leaving_date1']!=0)
    				$ld1=date("m/d/Y",$res_query[$i]['leaving_date1']);
    				
    			if(isset($res_query[$i]['leaving_date2']) && $res_query[$i]['leaving_date2']!=0)
    				$ld2=date("m/d/Y",$res_query[$i]['leaving_date2']);
    				
    			if(isset($res_query[$i]['leaving_date3']) && $res_query[$i]['leaving_date3']!=0)
    				$ld3=date("m/d/Y",$res_query[$i]['leaving_date3']);	
    					
				$result[$i]=array($res_query[$i]['ecode'],$res_query[$i]['user_type'],trim($res_query[$i]['first_name'])." ".$res_query[$i]['last_name'],$res_query[$i]['previous_employer1'],$jod1,$ld1,$res_query[$i]['experiance1'],$res_query[$i]['previous_employer2'],$jod2,$ld2,$res_query[$i]['experiance2'],$res_query[$i]['previous_employer3'],$jod3,$ld3,$res_query[$i]['experiance3']);
			}
		}
	}
    
    
}

include_once "excelwriter.php";